<template>
	<div class="padding-across-10" style="height:100%;margin-bottom: 100px" v-loading="loading" element-loading-text="拼命加载中">
		<div class="flex-inline">
			<headerOpreate :opreate-datas="opreateDatas" v-on:executeAction="executeAction"></headerOpreate>
			<div class="block" style="text-align:right;">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40, 50]" :page-size="pageSize" layout="total, sizes,prev, pager, next, jumper" :total="totalSize">
				</el-pagination>
			</div>
		</div>
		<div style="width: 100%;border: 1px solid gray;padding: 5px;margin: 3px 0;">
			<el-row v-if="machineCaptureDatas.length > 0" :gutter="10">
				<el-col :span="6" v-for="item in machineCaptureDatas" style="margin-top: 5px;">
					<div style="position:relative ">
						<div style="position:absolute; right: 0px; bottom:5px; color:#fff;background-color: #000;
															opacity: 0.5;font-size: 10px;border-radius: 3px;padding: 0px 5px;">{{item.time}}</div>
						<img style="border-radius: 5px;width:100%;" title="点击放大" v-bind:src="item.path" height="200" width="100%" @click="bigImg(item)" :onerror="newsImgLoadError(this)"/>
					</div>
				</el-col>
			</el-row>
			<div v-else style="text-align: center; color: #324157;">
				<h2>该设备暂无图像信息</h2>
			</div>
		</div>
		<div class="block" style="text-align:right;">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40, 50]" :page-size="pageSize" layout="total, sizes,prev, pager, next, jumper" :total="totalSize">
			</el-pagination>
		</div>
		<el-dialog :visible.sync="dialogImg" id="img-diglog" :show-close="false">
			<img v-bind:src="imgUrl" width="100%" height="100%" />
		</el-dialog>
	</div>
</template>

<script>
	import $ from 'jquery';
	import headerOpreate from '../../../../components/headerOpreate'
	import { GloabFun, HttpServer } from '../../../../assets/js/common.js'
	export default {
		components: {
			headerOpreate
		},
		data() {
			return {
				machineCaptureDatas: [],
				currentPage: 1,
				pageSize: 10,
				totalSize: 0,
				dialogImg: false,
				imgUrl: '',
				opreateDatas: [{
					show: true,
					size: "small",
					type: 'primary',
					icon: 'el-icon-eleg-icon_refresh el-icon--left',
					name: this.$t("message.refresh"),
					action: 'reloadDatas'
				}]
			}
		},
		props: {
			templateObj: {
				type: Object,
				default: {}
			}
		},
		methods: {
			executeAction(action) {
				if(action) {
					this[action]();
				}
			},
			newsImgLoadError(id) {
				// console.log(this)
			},
			bigImg(item) {
				this.dialogImg = true;
				this.imgUrl = item.path;
			},
			formateCaptureData(array) {
				for(var i = 0; i < array.length; i++) {
					var index1 = array[i].time.indexOf("T");
					array[i].time = array[i].time.substring(0, index1) + " " + array[i].time.substring(index1 + 1, index1 + 9);
				}
			},
			handleSizeChange(val) {
				this.pageSize = val;
				this.getDatas();
			},
			handleCurrentChange(val) {
				this.currentPage = val;
				this.getDatas();
			},
			reloadDatas() {
				HttpServer.httpPost.call(this, '/Api/MachineCapture/List', {
					sn: this.templateObj.sn,
					UserId: parseInt(GloabFun.getKeyId()),
					index: this.currentPage,
					pagesize: this.pageSize,
				}, function(response) {}, function(response) {
					if(response.data.code === 0) {
						this.formateCaptureData(response.data.list);
						this.machineCaptureDatas = response.data.list;
						this.totalSize = response.data.totalcount;
						this.$notify({
							title: '成功',
							message: this.$t('message.refreshSuccess'),
							type: 'success',
							duration: 2500
						});
					} else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				})
			},
			getDatas() {
				HttpServer.httpPost.call(this, '/Api/MachineCapture/List', {
					sn: this.templateObj.sn,
					UserId: parseInt(GloabFun.getKeyId()),
					index: this.currentPage,
					pagesize: this.pageSize,
				}, function(response) {}, function(response) {
					if(response.data.code === 0) {
						this.formateCaptureData(response.data.list);
						this.machineCaptureDatas = response.data.list;
						this.totalSize = response.data.totalcount;
					} else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				})
			}
		},
		created() {
			this.getDatas();
		}
	}
</script>

<style scoped>
	@import '../../../../assets/css/font-awesome-4.7.0/css/font-awesome.css';
</style>
<style scoped lang="less">
	@import '../../../../assets/css/media-screen.less';
</style>

<style scoped lang="less">
	* {
		box-sizing: border-box;
	}
</style>
<style lang="less" scope>
	.flex-inline {
		display: flex;
		justify-content: space-between;
		.query {
			display: flex;
		}
	}
	
	#img-diglog {
		/*.el-dialog__header {
			display: none !important;
		}
		.el-dialog--small {
			width: auto !important;
			padding-bottom: 30px !important;
		}
		.el-dialog__body {
			overflow: visible !important;
		}*/
		.el-dialog{
			background: none;
			box-shadow: none;
		}
		.el-dialog__body {
			overflow: visible !important;
		}
	}
</style>